<script setup lang="ts">
import { computed, useSlots } from "vue";
import ReTextTooltip from "@/components/ReTextTooltip";

const slots = useSlots();

interface Props {
  title: string;
  dark?: boolean;
  slotTitleWidth?: number | string;
  titleBgWidth?: number | string;
}

const props = withDefaults(defineProps<Props>(), { dark: false, titleBgWidth: 280 });
const title_bg_width = computed(() =>
  props.titleBgWidth
    ? typeof props.titleBgWidth === "number"
      ? `${props.titleBgWidth}px`
      : typeof props.titleBgWidth === "string"
        ? props.titleBgWidth
        : "280px"
    : "280px"
);
const slot_width = computed(() =>
  props.slotTitleWidth
    ? typeof props.slotTitleWidth === "number"
      ? `${props.slotTitleWidth}px`
      : typeof props.slotTitleWidth === "string"
        ? props.slotTitleWidth
        : "auto"
    : "auto"
);
</script>

<template>
  <div class="model-title-com" :class="{ 'model-title-com-dark': dark }">
    <div class="title-text"><ReTextTooltip :content="title" /></div>
    <div v-if="slots.middleTitle" class="title-slot-middle"><slot name="middleTitle" /></div>
    <div v-if="slots.default" class="title-slot"><slot /></div>
  </div>
</template>

<style lang="scss" scoped>
.model-title-com {
  display: flex;
  gap: 24px;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  height: 32px;
  // background: linear-gradient(90deg, var(--px-color-primary-light-9), #fff);
  background: linear-gradient(270deg, rgb(59 130 246 / 0%) 0%, rgb(59 130 246 / 24%) 100%) no-repeat;
  background-size: v-bind(title_bg_width);
  border-left: 4px solid var(--px-color-primary);

  .title-text {
    // flex: 1;
    // width: fit-content;
    min-width: 0;
    max-width: calc(100% - 32px);
    font-size: 18px;
    font-weight: 600;
    line-height: 1;
    color: #333;
    text-indent: 8px;
    user-select: none;
  }

  .title-slot-middle {
    min-width: 0;
    // max-width: 50%;
  }

  .title-slot {
    width: v-bind(slot_width);
    min-width: 0;
    // max-width: 50%;
  }
}

.model-title-com-dark {
  background: linear-gradient(90deg, #134169, #001e3b) no-repeat;
  background-size: 280px;
  border-color: #00c2ff;

  .title-text {
    color: #fff;
  }
}
</style>
